package wangm.repository;

import wangm.bean.ExaminationTopic;
import wangm.util.DBOperatorComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.List;

/**
 * T_PAPER_TOPIC_COMBINE 组合表(T_EXAMINATION_PAPER,T_EXAMINATION_TOPIC) repository
 *
 * @author zk
 * @date 2018-02-23 20:24
 */
@Repository
public class ExaminationPaperTopicRepository {
    private static Logger logger = LoggerFactory.getLogger(ExaminationPaperTopicRepository.class);

    public static final String thisTableName = "T_PAPER_TOPIC_COMBINE";
    /**
     * db operator
     */
    @Autowired
    DBOperatorComponent dbOperatorComponent;

    /**
     * 根据试卷id获取小题集合(不包括选项)
     *
     * @param pid pid
     * @return paperBean
     */
    public List<ExaminationTopic> getTopicListByPid(String pid){
        String querySql = "select * from " + ExaminationTopicRepository.thisTableName +
                " t where t.id in (select tid from " + thisTableName + " tc where tc.pid = ?);";
        try {
            return dbOperatorComponent.getBeanList(ExaminationTopic.class,querySql, pid);
        } catch (SQLException e) {
            logger.error("get the list of examinationTopic by pid fail : "+ e.getMessage(),e);
            return null;
        }
    }
}
